<?php
require_once "BaseController.php";

class IndexController extends BaseController {
	
	function init() {
		
		$this->_helper->layout->setLayout('layout');
		$this->view->huhu = "abc";
	}
	
	function doLoginAction() {
	
		$db = BaseController::getDBConnection();
		$db->getConnection();
		
		$auth = Zend_Auth::getInstance();
		$authAdapter = new Zend_Auth_Adapter_DbTable($db);
		$authAdapter->setTableName("user");
		$authAdapter->setIdentityColumn("name");
		$authAdapter->setCredentialColumn("passwd");
		
		$authAdapter->setIdentity($_POST["username"]);
		$authAdapter->setCredential($_POST["password"]);
		
		$result = $auth->authenticate($authAdapter);
		
		if ($result->isValid()) {
	 		$auth->getStorage()->write($authAdapter->getResultRowObject());
	 		$this->_redirect("history");
		}
		
		else {
			$auth->clearIdentity();
			$this->_helper->error_message = "wrong username";
			$this->_redirect("index");
		}
	}
	
	function indexAction() {

	

	}
			
}
